/*
 * @(#)Graph.java
 *
 * Revision:
 * Author                                         Date           
 * --------------------------------------------   ------------   
 *  Jeremias D. Serafim de Araujo                 06/02/2012    
 */
package br.edu.ufcg.splab.core.graph;


import java.util.UUID;

import br.edu.ufcg.splab.core.InterfaceEdge;
import br.edu.ufcg.splab.core.InterfaceVertex;
import br.edu.ufcg.splab.core.edges.Edge;
import br.edu.ufcg.splab.core.edges.EdgeType;
import br.edu.ufcg.splab.core.vertex.Vertex;
import br.edu.ufcg.splab.exceptions.LTSBTException;

/**
 * 
 * Class to represent a graph. 
 * @see abstracts.AbstractGraph
 * 
 * */
public class Graph extends AbstractGraph{

	/**
	 * Constructor
	 * @see abstracts.AbstractGraph
	 * 
	 */
	public Graph() {
		super();
	}
	
	/**
	 *
	 * Adds a vertex in graph with specified label
	 * Returns uuid because we need to create an edge,
	 * uuid vertex from and uuid vertex to
	 * 
	 * @param label is the label of vertex
	 * @return UUID
	 */

	public UUID addVertex(String label) {

		InterfaceVertex v = new Vertex(label);

		if (getStates().size() == 0) {
			setRoot(v);
			this.getStates().put(v.getUUID(), v);
		}

		this.getStates().put(v.getUUID(), v);
		return v.getUUID();
	}
	
	/**
	 *
	 * Create edge between the vertices specified with respective labelEdge
	 * and adds edge in graph
	 * 
	 * @param from is the id of vertex form
	 * @param to is the id of vertex to
	 * @param label is the name of label
	 * @param type is the type of edge
	 */
	public void createEdge(UUID from, UUID to, String labelEdge, EdgeType type) throws LTSBTException{
		InterfaceVertex vFrom = getStates().get(from);
		InterfaceVertex vTo = getStates().get(to);
		
//		System.out.println("vf "+vFrom);
//		System.out.println("vt "+vTo);
		if(vFrom==null || vTo==null){
			throw new LTSBTException("State was not specified for edge: \"" + labelEdge + "\"");
		}
		InterfaceEdge edge = new Edge(vFrom, labelEdge, vTo,type);
		vFrom.addEdgeOutTransitions(edge);
		vTo.addEdgeInTransitions(edge);
		this.getEdges().add(edge);
		
	}
	
	
//	public static void main(String[] args) {
//		Graph g = new Graph();
//		System.out.println(g.getRoot());
//		Vertex v = new Vertex("a");
//		g.addVertex("a");
//		g.addVertex("a");
//		//g.setRoot(v);
//		System.out.println(g.getRoot());
//		//g.setRoot(v);
//		System.out.println(g.getStates().size());
//		
//	}
	
}
